import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * User: Anastasia
 * Date: 13.02.15
 * Time: 10:56
 * To change this template use File | Settings | File Templates.
 */
public class Loader extends JFrame implements ActionListener {


    public void actionPerformed(ActionEvent arg0)
    {

        try{


            InetAddress addr = InetAddress.getByName(null);
            Socket socket = new Socket(addr, 8080);

            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
            out.writeObject(new Exchanger(71,null));
            //  System.out.println("Ok");

            out.flush();  //чудный метод.

            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
            Object object = in.readObject();


            String x = (String)object;

            if(x.equals("0"))
            {
                JOptionPane.showMessageDialog(null,"Список загружен", "OK",
                        JOptionPane.INFORMATION_MESSAGE);
            }

            else
            {
                JOptionPane.showMessageDialog(null,"Ошибка загрузки", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }


        catch (Exception e)
        {
            System.out.println("init error: " +e); // Print exception

            e.printStackTrace();
        }





    }

}

